home *** CD-ROM | disk | FTP | other *** search
- /* Source for Clibboard Utility */
- /* 1994 David B. Symolon */
-
- #include <dos.h>
- #include <FCNTL.H>
- #include <stdlib.h>
- #include <stdio.h>
- #include <io.h>
- #include <alloc.h>
- #include <string.h>
- #include "clipbrd.h"
-
- /* Number of command line parameters.*/
- #define NUM_PARAM 3
-
- /* Function prototypes */
- void main();
- void ClipB(char, char *);
- void readClip(char *);
- void pasteClip(char* );
-
- /* Usage string */
- char szUsage[] =
- "USAGE:\nclip <options> filename\nOPTIONS:\n c Copy to Clipboard \n p Paste from clipboard\n\n\nCLEAR to clear Clipboard.\n";
- char szMe[] =
- "DOS Clipboard Utility (c)1994 David B. Symolon\n21391 Town Lakes Dr. #1-16, Boca Raton, FL,33486\n\n";
- /* Code */
- void main(int *argc, char * argv[])
- {
- char *ans;
-
-
- if(strcmp(argv[1],"CLOSE") == 0) /*"Hidden" Call for debugging*/
- {
- printf(szMe);
- CloseClip();
- return;
- }
- if(strcmp(argv[1],"CLEAR") == 0)
- {
- printf(szMe);
- printf("Are you sure y/n?");
- gets(ans);
- if(*ans == 'y' || *ans == 'Y')
- {
- OpenClipBoard();
- ClearClipBoard();
- CloseClip();
- }
- return;
- }
-
- if( *argc < NUM_PARAM ){
- printf(szMe);
- printf(szUsage);
- }
- else if(*argv[1] == 'c' || *argv[1] == 'C')
- {
- printf(szMe);
- ClipB('c',argv[2]);
- }
-
- else if(*argv[1] == 'p' || *argv[1] == 'P')
- {
- printf(szMe);
- ClipB('p',argv[2]);
-
- }
- }
- /******************************************************************
- /*
- * FUNCTION: ClipB(char , char*)
- *
- * This function just switches between each clipboard function...
- *
- */
- void ClipB(char type, char *pFIle)
- {
- unsigned int iErrorcode;
-
-
- if( (iErrorcode = OpenClipBoard()) == 0 )
- {
- printf("Unable to open clipboard ERROR CODE: %i\n",iErrorcode);
- return;
- }
-
- switch (type)
- {
- case 'c':
- readClip(pFIle);
- break;
- case 'p':
- pasteClip(pFIle);
- break;
- default:
- exit (1);
- }
-
- if( (iErrorcode = CloseClip()) == 0)
- printf("Unable to close clipboard - ERROR CODE: %d\n",iErrorcode);
-
-
- }
-
- /***********************************************************************/
- /*
- *
- * FUNCTION: pasteClip(char * pFIle)
- *
- * This function pastes frm the Window's Clipboard and places it into
- * the specified file.
- *
- */
- void pasteClip(char *pFIle)
- {
- unsigned int iErrorcode;
- void * OutBuffer;
- long Clipsize;
- long lClipSize;
- FILE * Out;
-
- if((Clipsize = QueryClip(OEM)) == 0)
- {
- printf("Clipboard is empty!\n");
- return;
- }
-
- else if( ( OutBuffer = (void *)malloc( Clipsize )) == NULL )
- {
- printf("Not enough RAM for buffer!\n");
- return;
- }
-
- if((iErrorcode = PasteFrmClip(OEM, OutBuffer )) == 0)
- {
- printf("Error code from Paste %d\n",iErrorcode);
- return;
- }
-
- if(( Out = fopen(pFIle,"a+b" )) != NULL )
- {
- fwrite( OutBuffer,Clipsize,1,Out );
- fclose(Out);
-
- }
-
- }
-
- /********************************************************************/
- /*
- *
- * FUNCTION: readClip(char * pFIle)
- *
- * This function reads a text file and then puts it into the Windows
- * Clipboard to be pasted somwhere ?
- *
- */
- void readClip(char * pFIle)
- {
- unsigned int iErrorcode;
- void * InBuffer;
- int filehandle;
- long Filesize;
- long lClipSize;
- FILE * In;
-
- filehandle = open( pFIle, O_RDONLY ); /*Get length of file*/
- Filesize = filelength( filehandle );
- close(filehandle);
-
- if ( (lClipSize = CompactClip( Filesize )) == 0)
- {
- printf("CompactClip returned the following %ld\n",lClipSize);
- return;
- }
- if( lClipSize < Filesize)
- {
- printf("Clipboard not big enough to hold file!");
- return;
- }
- if( (InBuffer = (void *)malloc( Filesize+1 )) == NULL )
- {
- printf("Not enough RAM for buffer!\n");
- return;
- }
-
- if( (iErrorcode = ClearClipBoard()) == 0 )
- {
- printf("Unable to clear clipboard ERROR CODE: %d\n",iErrorcode);
- return;
- }
-
-
- if(( In = fopen(pFIle,"r" )) != NULL )
- {
- fread( InBuffer,Filesize,1,In );
- fclose(In);
-
- if( (iErrorcode = CopyToClip(OEM,Filesize, InBuffer)) == 0)
- {
- printf("This is the code from the copy %i\n",iErrorcode);
- return;
- }
- }/* IF FOPEN*/
- }
-